<template>

      <div class="messageFrom">

		<el-table :data="tableData" height="600px" border style="width: 100%">
        <el-table-column prop="ISBN" label="图书编号" width="180">
        </el-table-column>
        <el-table-column prop="bookName" label="书籍名称" width="180">
        </el-table-column>
        <el-table-column prop="author" label="作者" width="180">
        </el-table-column>
        <el-table-column prop="press" label="出版社"width="180">
        </el-table-column>
         <el-table-column prop="borrowtime" label="借书时间" width="280">
        </el-table-column>
      <el-table-column label="操作" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">还书</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">续借</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>
</template>
<script>
export default {
  name: "myallborrow",
  data() {
    return {
      tableData: []
    };
  },
  //   mounted: function() {
  //       this.createdAlluser()
  //   },
  created: function() {
    this.table();
  },
  methods: {
    table: function() {
      var params = new URLSearchParams();
      params.append('username', this.$store.state.token);
      this.$axios({
        method: "post",
        url: "http://localhost:8080/myborrowBook.do",
        data: params
      })
        .then(response => {
          var data = [];
          for (var i = 0; i < response.data.data.length; i++) {
            var dataone = {};
            dataone.ISBN = response.data.data[i].ISBN;
            dataone.author = response.data.data[i].author;
            dataone.borrowtime = response.data.data[i].borrowtime;
            dataone.press = response.data.data[i].press;
            dataone.bookName = response.data.data[i].bookName;

            data.push(dataone);
          }
          this.tableData = data;

          if (response.data.data.length == 0) {
            alert("你没有借书");
          }
          console.log(response.data.data);
          console.log(response.data.code);
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    inf: function() {
      var params = new URLSearchParams();
      params.append('username', this.$store.state.token);
      params.append('username', this.tableData.dataone.ISBN);
      this.$axios({
        method: "post",
        url: "http://localhost:8080/returnBook.do",
        data: params
      })
        .then(response => {
          var data = [];
          for (var i = 0; i < response.data.data.length; i++) {
            var dataone = {};
            dataone.ISBN = response.data.data[i].ISBN;
            dataone.author = response.data.data[i].author;
            dataone.borrowtime = response.data.data[i].borrowtime;
            dataone.press = response.data.data[i].press;
            dataone.bookName = response.data.data[i].bookName;

            data.push(dataone);
          }
          this.tableData = data;

          if (response.data.data.length == 0) {
            alert("你没有借书");
          }
          console.log(response.data.data);
          console.log(response.data.code);
        })
        .catch(function(error) {
          console.log(error);
        });
    console.log(this.tableData)
    },
    search: function() {
      console.log(this.value + this.input);
      if (this.value == "" || this.input == "") {
        alert("请选择你要输入的值");
      } else {
        this.table();
      }
    },
    handleEdit(index, row) {
    console.log(index, row);
    var params = new URLSearchParams();
      params.append('username', this.$store.state.token);
      params.append('IBSN', row.ISBN);
      this.$axios({
        method: "post",
        url: "http://localhost:8080/returnBook.do",
        data: params
      })
        .then(response => {
          var data = [];
          for (var i = 0; i < response.data.data.length; i++) {
            var dataone = {};
            dataone.ISBN = response.data.data[i].ISBN;
            dataone.author = response.data.data[i].author;
            dataone.borrowtime = response.data.data[i].borrowtime;
            dataone.press = response.data.data[i].press;
            dataone.bookName = response.data.data[i].bookName;

            data.push(dataone);
          }
          this.tableData = data;

          if (response.data.data.length == 0) {
            alert("你没有借书");
          }
          console.log(response.data.data);
          console.log(response.data.code);
        })
        .catch(function(error) {
          console.log(error);
        });

    },
    handleDelete(index, row) {
        console.log(index, row);
    }
  }
};
</script>

<style scoped>
.messageFrom {
  width: 100%;
  height: 100%;
}
.content {
  width: 500px;
  height: 100%;
  max-height: 500px;
  margin: 0 auto;
}
.searchcontent {
  width: 100%;
}
.choice {
  float: left;
  width: 180px;
}
.searchinput {
  width: 250px;
  float: left;
  margin-left: 50px;
}
</style>
